package display;

import java.awt.Container;
import java.util.Observable;
import java.util.Observer;

import universe.Game;

public class GameDisplay implements Observer{

		private BoardDisplay theBoardDisplay;
		private BlockDisplay theBlockDisplay;
		private PauseDisplay thePauseDisplay;

		
		private Game		theGame;
		private Container	theContainerGame;

		public GameDisplay(Container pContainerGame, Game pGame) {
			super();
			this.setGame(pGame);
			this.setContainerGame(pContainerGame);
			
			this.thePauseDisplay = new PauseDisplay(this.getContainerGame());
			this.theBlockDisplay = new BlockDisplay(this.getContainerGame(), this.getGame().getCurrentBlockHandler());
			this.theBoardDisplay = new BoardDisplay(this.getContainerGame(), this.getGame());
			
			
		}
		
		@Override
		public void update(Observable o, Object arg) {
			
			// Ceci est un gros test de ouf mais il le faut en fait !
			this.theBlockDisplay.setBlockHandler(this.getGame().getCurrentBlockHandler());
			if(theGame.isGamePaused()){
				thePauseDisplay.setVisible(true);
			}
			else {
				thePauseDisplay.setVisible(false);
			}
			this.getContainerGame().repaint();
		}
		

		public void setGame(Game pGame) {
			if(theGame!=null){
				theGame.deleteObserver(this);
			}
			this.theGame = pGame;
			pGame.addObserver(this);
			pGame.getBoard().addObserver(this);
		}

		public Game getGame() {
			return theGame;
		}

		public void setContainerGame(Container pContainerGame) {
			this.theContainerGame = pContainerGame;
		}

		public Container getContainerGame() {
			return theContainerGame;
		}
		

		public void clear(){
			
			theGame.deleteObserver(this);
			theGame = null;
			
			theBlockDisplay = null;
			
			theBoardDisplay = null;
			
		}
}
